package com.cx.base.day08_字符串;

import java.util.*;

public class StringDemo<chars> {
    public static void main(String[] args) {

//    String 的常用情况：
//    1、常量池存储
        String str1 = "ssffaf";
//    2、堆存储
        String str2 = new String(str1);
        System.out.println(str1 == str2);
        String str1_append = "ss";
        String str2_append = "ffaf";
        System.out.println(str1 == str1_append + str2_append);
        String str211 = str1;
        System.out.println(str1 == str211);
        char[] chars = new char[5];
        chars[0] = '1';
        chars[1] = '2';
        chars[2] = '3';
        chars[3] = '4';
        chars[4] = '5';
        String str3 = new String(chars);
        String str4 = new String(str3);
        System.out.println(String.valueOf(chars));
//      3、常用方法
        System.out.println(str3.charAt(2));
        System.out.println(str3.substring(3));
        System.out.println(str3.indexOf(1));
        System.out.println(str3.indexOf('2'));
        System.out.println(str3.indexOf("23"));
        System.out.println(str3.equals(str4));
        System.out.println(str3.equalsIgnoreCase(str4));
        System.out.println(str3.compareTo(str4));
        System.out.println(str3.compareToIgnoreCase(str4));
//        String 的常用方法：
//        创建对象
        String str11 = "sssssss";
//        堆内存创建对象
        String str21 = new String(str1);
//        靠有参构造函数创建
        String str31 = new String(str2);
//        靠字符数组作有参创建
        String str41 = new String(new char[]{'n', 'g', 'a', 's'});
//常用方法
        System.out.println(str41.charAt(0));
        System.out.println(str41.equals(str31));
        System.out.println(str41.compareTo(str31));
        System.out.println(str41.indexOf(1));
        System.out.println(str41.indexOf("ga"));
        System.out.println(str41.concat(str11));
        System.out.println(str41.trim());
        System.out.println(str41.split("g"));
        System.out.println(str41.valueOf("可以传多种类型值，比如boolean,int"));
        System.out.println(str41.replace("s", "jihss"));
//        StringBuffer 无参构造长度默认16
        StringBuffer sb = new StringBuffer();
//        StringBuffer 有参构造，长度为有参长度+16
        StringBuffer sb2 = new StringBuffer("ghhw2");
        System.out.println(sb2.append(22));
        System.out.println(sb2.insert(2, "kjaghaghag"));
        System.out.println(sb2.replace(1, 10, "oa"));
        ;
//        含前不含后
        System.out.println(sb2.delete(1, 3));
        System.out.println(sb2.reverse());
//        创建对象
        String str = "ta0hgafghjajhfhfhjahgahgahgjhjag";
        String str12 = new String(str);
        String str22 = new String("hgjahgahgakg");
        String str32 = new String(new char[]{'s', 's', 's', 'k', 'n', 'p'});
        System.out.println(str12.charAt(0));
        System.out.println(str.equals(str12));
        System.out.println(str.compareTo(str12));
        System.out.println(str.length());
        System.out.println(str.endsWith("hjag"));
        System.out.println(str.startsWith("tahg", 0));
        System.out.println(str.indexOf("tahg"));
        System.out.println(str.indexOf(0));
//        StringBuffer，可变，线程安全

        StringBuffer sb3 = new StringBuffer();
        sb3.append("kkkkk");
        sb3.insert(3, 1141);
        System.out.println(sb3);
        sb3.delete(6, 9);
        System.out.println(sb3);
        System.out.println(sb3.replace(3, 5, "thagkahgahg"));


    }

}
